package com.ruoyi.project.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.HePatient;
import com.ruoyi.project.service.IHePatientService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 患者信息
Controller
 * 
 * @author ruoyi
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/patient")
public class HePatientController extends BaseController
{
    @Autowired
    private IHePatientService hePatientService;

    /**
     * 查询患者信息
列表
     */
    @RequiresPermissions("project:patient:list")
    @GetMapping("/list")
    public TableDataInfo list(HePatient hePatient)
    {
        startPage();
        List<HePatient> list = hePatientService.selectHePatientList(hePatient);
        return getDataTable(list);
    }

    /**
     * 导出患者信息
列表
     */
    @RequiresPermissions("project:patient:export")
    @Log(title = "患者信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HePatient hePatient)
    {
        List<HePatient> list = hePatientService.selectHePatientList(hePatient);
        ExcelUtil<HePatient> util = new ExcelUtil<HePatient>(HePatient.class);
        util.exportExcel(response, list, "患者信息数据");
    }

    /**
     * 获取患者信息
详细信息
     */
    @RequiresPermissions("project:patient:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hePatientService.selectHePatientById(id));
    }

    /**
     * 新增患者信息

     */
    @RequiresPermissions("project:patient:add")
    @Log(title = "患者信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HePatient hePatient)
    {
        return toAjax(hePatientService.insertHePatient(hePatient));
    }

    /**
     * 修改患者信息

     */
    @RequiresPermissions("project:patient:edit")
    @Log(title = "患者信息 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HePatient hePatient)
    {
        return toAjax(hePatientService.updateHePatient(hePatient));
    }

    /**
     * 删除患者信息

     */
    @RequiresPermissions("project:patient:remove")
    @Log(title = "患者信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hePatientService.deleteHePatientByIds(ids));
    }
}
